package com.lxf.cloudotherserve.controller;

import com.alibaba.fastjson.JSONObject;
import com.lxf.cloudotherserve.annotate.OtherRateLimit;
import com.lxf.cloudotherserve.service.PlayHistoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @author 罗兴发
 * @data 2025/6/27 17:47
 * @description：浏览记录-控制层
 */
@RestController
@CrossOrigin  //跨域
@RequestMapping("/v1")
@Slf4j
public class PlayHistoryController {

    @Resource
    PlayHistoryService  playHistoryService;

    /**
     * 添加浏览记录
     * @param json
     * @return
     */
    @PostMapping("/addPlayHistory")
    public String addPlayHistory(@RequestBody JSONObject json,HttpServletRequest request){
        return playHistoryService.addPlayHistory(json,request);
    }

    /**
     * 获取浏览记录
     * 传递用户ID获取内容ID，根据两者其中之一查询即可
     * 不可同时传递
     * @param json
     * @return
     */
    @OtherRateLimit(value = 2,timeout = 5)
    @PostMapping("/getPlayHistoryById")
    public String getPlayHistoryById(@RequestBody JSONObject json){
        return playHistoryService.getPlayHistoryById(json);
    }

    /**
     * 根据用户ID删除/清空浏览记录
     * @param json
     * @return
     */
    @OtherRateLimit(value = 2,timeout = 5)
    @PostMapping("/updatePlayHistoryById")
    public String updatePlayHistoryById(@RequestBody JSONObject json, HttpServletRequest request){
        return playHistoryService.updatePlayHistoryById(json,request);
    }

    /**
     * 根据ID和类型清空浏览记录（但不清除有用户ID的）
     * @param json
     * @return
     */
    @OtherRateLimit(value = 2,timeout = 5)
    @PostMapping("/deletePlayHistoryByIdAndType")
    public String deletePlayHistoryByIdAndType(@RequestBody JSONObject json){
        return playHistoryService.deletePlayHistoryByIdAndType(json);
    }
}
